/**
 * Created by zzy on 2018/2/8.
 */
import React, {Component} from 'react';
import {
    Text,
    View,
    TouchableOpacity,
    DeviceEventEmitter,
    TextInput,
    StyleSheet,
    Button,
    ScrollView,
    Dimensions
} from 'react-native';
import Constant from "../../js/Contant";
import {GradientButton} from "../../js/component/Button";
import RequestUtil from "../../js/util/NetUtil";
import loginStore from "../store/LoginStoreLuo";
import {ResetRouter} from "../../js/router/RouterUtil";
const ScreenW = Dimensions.get('window').width;
const Attention =()=> {
    return <View style={{justifyContent:'center',alignItems:'center',height:100}}>
        <Text style={{fontSize:15,color:'rgba(51,51,51,1)'}}>请设置密码</Text>
    </View>
};

const LoginBtn = ({onPress})=>{
    return  <View style={{height: 40, paddingHorizontal: 15,marginTop:35}}>
        <GradientButton
            onPress={onPress}
            title="下一步"/>
    </View>
}


const Input = ({value,title='', placeholder, onChangeText, keyboardType = 'default', secureTextEntry = false}) => {
    return <View>
        <View style={{flexDirection:'row',alignItems:'center',paddingHorizontal:15,height:50,backgroundColor:'white'}}>
            <View style={{flex:1}}>
                <Text style={{fontSize:14,color:'rgba(51,51,51,1)'}}>{title}</Text>
            </View>
            <View style={[{marginLeft:10,height:40,backgroundColor: 'white',flex:5}]}>
                <TextInput
                    clearTextOnFocus={true}
                    style={{fontSize:14,fontWeight:'400',height:40,color:'rgba(51,51,51,1)'}}
                    value={value}
                    keyboardType={keyboardType}
                    secureTextEntry={secureTextEntry}
                    placeholder={placeholder}
                    onChangeText={onChangeText}/>
            </View>
        </View>
        <View style={{flexDirection:'row',marginLeft:12,width:ScreenW-24,height:0.5,backgroundColor:'rgba(217,217,217,1)'}}/>
    </View>
}



export default class SetPassword extends Component{

    constructor(props){
        super(props);
        this.pwd = null ;
    }

    render(){
        return <View style={{flex:1}}>
            <Input
                title='密码'
                placeholder='请填写密码'
                onChangeText={text=>{
                    this.pwd = text ;
                }}
            />
            <LoginBtn onPress={()=>{
                if(this.pwd == null)return;
                let pwd = this.pwd ;
                let navigation = this.props.navigation ;
                RequestUtil.requestData('login/setPassword', {
                    password: pwd,
                }).then(token => {
                    ResetRouter(navigation);
                }).catch(err => {
                    alert(err);
                });
            }}/>
        </View>
    }
}
const styles = {
    borderBottom: {
        borderBottomColor: Constant.SEPLINECOLOR,
        borderBottomWidth: StyleSheet.hairlineWidth
    },
}
